import Layout from "../views/Layout-page";
import Home from "../views/Home";

/**
 * 需要权限才可访问
 */
export const routerMap = [
	{
		// 命名路由
		path: '/',
		name: 'home',
		// 别名
		// alias: '/home_page',
		component: Layout,
		meta: {title: '首页'},
		// children: [
		// 	{
		// 		path: 'folder_tree',
		// 		name: 'folder_tree',
		// 		component: () => import('@/views/folder-tree/Folder-tree.vue')
		// 	}
		// ]
		children: [
			{
				path: 'home',
				name: 'home_index',
				meta: {title: '首页'},
				component: Home
			}
		]
		// component: Home,
		// 路由组件传参，函数模式
		// props: route => ({
		// 	food: route.query.food
		// }),
		// beforeEnter: (to, from, next) => {
		// 	// if (from.name === 'about') alert('from about page');
		// 	// else alert('not from about page');
		// 	next();
		// }
	}, {
		path: '/about',
		name: 'about',
		// route level code-splitting
		// this generates a separate chunk (about.[hash].js) for this route
		// which is lazy-loaded when the route is visited.
		component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue'),
		// 路由组件传参，对象模式
		props: { food: 'peach'},
		// 路由元信息
		meta: {title: '关于'}
	},
	/*{
		// 动态路由
		path: '/argu/:name',
		name: 'argu',
		component: () => import('@/views/Argu.vue'),
		// 路由组件传参：boolean 模式
		props: true
	},*/
	{
		// 嵌套路由
		path: '/parent',
		name: 'parent',
		meta: {title: 'parent'},
		component: () => import('@/views/Parent.vue'),
		children: [
			{
				path: 'child',
				name: 'child',
				meta: {title: 'child'},
				component: () => import('@/views/Child.vue')
			}
		]
	}, {
		// 命名视图
		path: "/named_view",
		name: 'named_view',
		meta: {title: 'named_view'},
		components: {
			default: () => import('@/views/Child.vue'),
			email: () => import('@/views/Email.vue'),
			tel: () => import('@/views/Tel.vue')
		}
	}, {
		// 重定向
		path: '/main',
		name: 'main',
		meta: {title: 'main'},
		// redirect: '/'

		// 命名路由的方式
		// redirect: {name:'home'}

		// 方法函数的方式
		// redirect: to => {
		// console.log(to)
		// return { name: 'home' }
		// return '/'
		// }
		redirect: to => '/'
	}, {
		path: '/store',
		name: 'store',
		meta: {title: 'store'},
		component: () => import('@/views/Store.vue')
	}, {
		path: '/count_to',
		name: 'count_to',
		meta: {title: 'count_to'},
		component: () => import('@/views/Count-to.vue')
	}, {
		path: '/split_pane',
		name: 'split_pane',
		meta: {title: 'split_pane'},
		component: () => import('@/views/Split-pane.vue')
	}, {
		path: '/render_page',
		name: 'render_page',
		meta: {title: 'render_page'},
		component: () => import('@/views/Render-page.vue')
	}, {
		path: '/menu_page',
		name: 'menu_page',
		meta: {title: 'menu_page'},
		component: () => import('@/views/Menu-page.vue')
	},
	/*{
		path: '/table',
		name: 'table',
		meta: {title: 'table'},
		component: () => import('@/views/Table.vue')
	},*/
	{
		path: '/upload',
		name: 'upload',
		meta: {title: 'upload'},
		component: () => import('@/views/Upload.vue')
	}, {
		path: '/form',
		name: 'form',
		meta: {title: 'form'},
		component: () => import('@/views/Form.vue')
	}, {
		path: '/dynamic_form',
		name: 'dynamic_form',
		meta: {title: 'dynamic_form'},
		component: () => import('../views/Dynamic-form.vue')
	}, {
		path: '/optimize',
		name: 'optimize',
		meta: {title: 'optimize'},
		component: () => import('@/views/Optimize.vue')
	}, {
		path: '/component',
		name: 'component',
		component: Layout,
		meta: {title: '表格'},
		children: [
			{
				path: 'table',
				name: 'table',
				meta: {title: '表格'},
				component: () => import('@/views/Table.vue')
			}, {
				path: 'folder_tree',
				name: 'folder_tree',
				meta: {title: '文件夹'},
				component: () => import('@/views/folder-tree/Folder-tree.vue')
			}, {
				path: 'params/:id',
				name: 'params',
				meta: {title: '参数'},
				component: () => import('@/views/Argu.vue'),
				props: true
			}
		]
	}
]

/**
 * 不需要权限控制
 */
export const routes = [
	{
		path: '/login',
		name: 'login',
		component: () => import('@/views/Login.vue')
	}, {
		path: '/icon_page',
		name: 'icon_page',
		meta: {title: '图标'},
		component: () => import('@/views/Icon_page.vue')
	}, {
		// 错误页面
		path: '*', // 匹配任何路径
		component: () => import('@/views/Error_404.vue')
	}
];
